/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package labbd_._projetofinal;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import oracle.jdbc.OracleCallableStatement;
import oracle.jdbc.OracleConnection;
import oracle.jdbc.OracleResultSet;
import oracle.jdbc.OracleTypes;

/*
 *
 * @author Rafael
 * TODO tratar as excecoes sql
 */
public class DataBase {
	private OracleConnection conn = null;
	private ResultSet result = null;
	
	public final static int LOGIN_INVALIDO = 20003;
	public final static int SENHA_INVALIDA = 20002;
	public final static int CPF_INVALIDO = 20004;
	public final static int CAMPO_EXISTENTE = 20001;
	public final static int CARTAO_VENCIDO = 20012;
	

	/*
	 * Construtor. Sua funcao eh iniciar uma conexao com a base de dados.
	 */
	public DataBase() throws ClassNotFoundException, SQLException{
		String naka = "r6793198";
		String bianca = "b6810554";
		String pswd = "labbd";
		String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
					//jdbc:oracle:thin:@server : port :SID
		
		Class.forName("oracle.jdbc.driver.OracleDriver");
		
		System.err.println("Conectando");
		conn = null;
		try {
			conn = (OracleConnection) DriverManager.getConnection(url, naka, pswd);
		} catch (SQLException ex) {
			System.err.println ("Nao foi possivel conectar ao servidor");
			throw ex;
		}
	}
	
	public OracleConnection getConnection () {
		return conn;
	}
	
	/*
	 * Fecha a conexao.
	 * 
	 * @throws SQLException 
	 */
	public void closeConnection() throws SQLException{
		if (conn != null) {
			System.err.println ("Desconectando");
			conn.close();
		}
	}
	/*
	 * Retorna o valor do result set.
	 */
	public ResultSet getResult() {
		return result;
	}

	public static void main (String args[]) {
		
	}

}
